/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mygame;

import java.util.ArrayList;
import mygame.Units.Ally;
import mygame.Units.Enemy;
import mygame.Units.Player;
import mygame.Units.Unit;

/**
 *
 * @author Ricardo
 */
public class World {
    
    public static Player player;
    public static ArrayList<Ally> allies = new ArrayList<Ally>(); 
    public static ArrayList<Enemy> enemies= new ArrayList<Enemy>();
 
    public static Player getPlayerByName(String name){
        if(player.name.equals(name)) return player;
        return null;
    }
    
    public static Ally getAllyByName(String name){
        for (Ally ally : allies) {
            if(ally.name.equals(name)) return ally;
        }
        return null;
    }
    
    public static Enemy getEnemyByName(String name){
        for (Enemy enemy : enemies) {
            if(enemy.name.equals(name)) return enemy;
        }
        return null;
    }
    
    public static Unit getUnitbyName(String name){
        Unit u = getPlayerByName(name);
        if(u!=null) return u;
        u=getEnemyByName(name);
        if(u!=null) return u;
        u=getAllyByName(name);
        if(u!=null) return u;
        return null;
    }
}
